import React from 'react'
import { Layout,Image} from 'antd';
import Table from '../Table'
import Editor from "../Editor"
import "./tr.css"
import {useSelector,useDispatch,connect} from 'react-redux'


const {Content} = Layout;

const Enviro = () => {

  const nearbyList = useSelector(state=> state.nearby.nearbyList)
  const valueList = useSelector(state=> state.value.valueList)
  const dispatch = useDispatch()

  const columns = [
    {
      title: '推荐名称',
      key: 'recomName',
      dataIndex: 'recomName',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '推荐图片',
      key: 'recomImg',
      dataIndex: 'recomImg',
      ellipsis:true,
      hideInSearch:true,
      render:(text,record)=>{
        if((record.recomImg).search(';') == -1){
          return(
            <Image.PreviewGroup>
              <Image width={30} height ={30} src={record.recomImg} />
            </Image.PreviewGroup>
          )

        }else{
          return (
            <Image.PreviewGroup>
              {
                (record.recomImg).split(";").map((items, index) =>{
                  return <Image width={30} height ={30} src={items} />

                }
                )
              }
            </Image.PreviewGroup>
            
          )
        }
      }
    },
    {
      title: '推荐介绍',
      key: 'recomItro',
      dataIndex: 'recomItro',
      valueType: 'text',
      ellipsis:true
    },
    {
        title: '操作',
        key: 'option',
        width: 120,
        valueType: 'option',
        render: (text,record,index,action) => [<div onClick={()=>{
          dispatch({type:'get',con:record});console.log(valueList)
        }}><Editor ques={enviro} url="http://49.233.107.127:2002/city/enviro"/></div>
        , <a onClick={async ()=>{
          console.log(record)
          await fetch(`http://49.233.107.127:2002/city/enviro/${record.recomID}/${record.cityID}`,{
          method:'delete',
          headers: {
            'Content-Type': 'application/json;charset=UTF-8'
          }
        })
        dispatch({type:'delete',content:['delete']})
        }}>删除</a>]
      }];

    const right = {}

    const enviro = [
      {name:'cityID',label:'城市id',tooltip:'最长为24位',placeholder:'输入城市id'},
      {name:'recomID',label:'推荐列表id',tooltip:'最长为24位',placeholder:'请输入推荐列表id'},
      {name:'recomName',label:'推荐名称',tooltip:'最长为24位',placeholder:'输入景点名称'},
      {name:'recomImg',label:'推荐图片',placeholder:'上传图片'},
      {name:'recomItro',label:'推荐介绍',placeholder:'输入景点介绍'},
      {name:'type',label:'类型',placeholder:'请输入类型'}
  ]
    return (
        <Content className="site-layout-background" style={{paddingLeft: 10,margin: 0,minHeight: 280,}}>
          {/* <h3>周边推荐管理</h3> */}
          <Table title="周边推荐管理" columns={columns} right={right} url="http://49.233.107.127:2002/city/enviro" ques={enviro}/>
        </Content>
    )
}

export default connect()(Enviro)
